import { NodeRoot } from "../Base/NodeRoot";
import { NMNode } from "../Base/NodeGraph";
@NMNode
export class PlayAnimation extends NodeRoot{
    public AnimationName:string;
    public Node: cc.Node;
    public IsLoop:boolean;
    public TimeScale:number;
    private isCompleted=false;
    private spineComp:sp.Skeleton;
    onEnter(){
        let animNode=this.Node;
        if(animNode){
            this.spineComp=animNode.getComponent(sp.Skeleton);
        }
        else{
            this.spineComp=this.ownerNode.getComponent(sp.Skeleton);
        }
        this.spineComp.timeScale=this.TimeScale;
        this.spineComp.setAnimation(0,this.AnimationName,this.IsLoop);
        this.spineComp.setCompleteListener(()=>{this.isCompleted=true;});
        console.log("播放动画",this.Node,this.AnimationName,this.IsLoop,this.spineComp);
    }
    onStep(dt:number){
        if(!this.IsLoop){
            if(this.isCompleted){
                console.log("播放完动画",this.Node,this.AnimationName,this.IsLoop,this.spineComp);
            }
            return this.isCompleted;
        }
        else{
            return this.spineComp.animation==this.AnimationName;
        }
    }
}